package com.mdb.open.trade.service.product;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdb.bc.database.mybatisplus.SuperService;
import com.mdb.enums.CustomerTypeEnum;
import com.mdb.open.trade.common.MdbDataSource;
import com.mdb.open.trade.domain.po.product.LimitUserProd;
import com.mdb.open.trade.mapper.product.LimitUserProdMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类描述：
 *  用户产品额度表 服务类
 *
 * @author liuyi
 * @date 2019-07-08
 */
@Service
@DS(MdbDataSource.PRODUCT)
public class LimitUserProdService extends SuperService<LimitUserProdMapper, LimitUserProd> {


    public List<LimitUserProd> listMerchantLimit(String customerCode, String prodCode) {
        return this.list(new QueryWrapper<LimitUserProd>().lambda()
                .eq(LimitUserProd::getType, CustomerTypeEnum.MERCHANT.getValue())
                .eq(LimitUserProd::getProdCode, prodCode)
                .eq(LimitUserProd::getPUserNo, customerCode));
    }

    public LimitUserProd getMerchantLimit(String customerCode, String prodCode, String merchantNo) {
        return this.getOne(new LambdaQueryWrapper<LimitUserProd>()
                .eq(LimitUserProd::getType, CustomerTypeEnum.MERCHANT.getValue())
                .eq(LimitUserProd::getProdCode, prodCode)
                .eq(LimitUserProd::getPUserNo, customerCode)
                .eq(LimitUserProd::getUserNo, merchantNo));
    }

    public LimitUserProd getCustomerLimit(String customerCode, String prodCode) {
        return this.getOne(new LambdaQueryWrapper<LimitUserProd>()
                .eq(LimitUserProd::getProdCode, prodCode)
                .eq(LimitUserProd::getType, CustomerTypeEnum.CUSTOMER.getValue())
                .eq(LimitUserProd::getUserNo, customerCode));
    }

    public LimitUserProd getCustomerLimitByLimitNo(String limitNo) {
        return this.getOne(new LambdaQueryWrapper<LimitUserProd>()
                .eq(LimitUserProd::getLimitNo, limitNo)
                .eq(LimitUserProd::getType, CustomerTypeEnum.CUSTOMER.getValue()));
    }
}
